package component

import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelStore
import com.example.ui_design.R
import component.base.BaseComponent

class BookItemComponent(itemView: View, viewModelStore: ViewModelStore, lifecycleOwner: LifecycleOwner
) :
  BaseComponent<BookViewModel>(viewModelStore, lifecycleOwner) {

  private val mContext = itemView.context
  private val name: TextView = itemView.findViewById(layoutId())
  val bookViewModel: BookViewModel = BookViewModel()

  public fun bind(lifeCycleOwner: LifecycleOwner) {
    bookViewModel.getBook().observe(lifeCycleOwner) {
      name.text = it.name
    }
  }

  override fun layoutId(): Int {
    return R.id.book_name
  }

  override fun init() {
    TODO("Not yet implemented")
  }

  override fun context(): Context {
    TODO("Not yet implemented")
  }

  override fun rootView(): View {
    TODO("Not yet implemented")
  }

  override fun createVM(viewModelClass: Class<BookViewModel>): BookViewModel {
    return super.createVM(BookViewModel::class.java)
  }

  override fun <X : ViewModel> onViewModelCreate(modelClass: Class<X>): X? {
    return BookViewModel() as X?
  }

  override fun bind() {
    TODO("Not yet implemented")
  }

  override fun unbind() {
    TODO("Not yet implemented")
  }

  override fun onAttach() {
    TODO("Not yet implemented")
  }

  override fun onDetach() {
    TODO("Not yet implemented")
  }


}